package com.example.capturetheflag.helper;

import java.util.ArrayList;
import java.util.List;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.OverlayItem;

public class SitesOverlay extends ItemizedOverlay<CustomItem> {
	  
    public SitesOverlay() {
		super(null);
		// TODO Auto-generated constructor stub
	}

	private List<CustomItem> items=new ArrayList<CustomItem>();
    
    public void add(int latitude,int longitude,String name,int resource,View v) {
      items.add(new CustomItem(new GeoPoint(latitude,longitude),name, getMarker(resource,v)));
      populate();
    }
    
    public void clear(){
    	items.removeAll(items);
    }
    
    @Override
    protected CustomItem createItem(int i) {
      return(items.get(i));
    }
    
    @Override
    public void draw(Canvas canvas, MapView mapView,
                      boolean shadow) {
      super.draw(canvas, mapView, shadow);
      
    }
    
    @Override
    public int size() {
      return(items.size());
    }
    
    private Drawable getMarker(int resource, View t) {
      Drawable marker = t.getResources().getDrawable(resource);
      
      marker.setBounds(0, 0, marker.getIntrinsicWidth(),
                        marker.getIntrinsicHeight());
      boundCenter(marker);

      return(marker);
    }
    
    private GeoPoint getPoint(double lat, double lon) {
        return(new GeoPoint((int)(lat*1000000.0),
                              (int)(lon*1000000.0)));
    }

  }
  
  